package com.rpc.center.event.manager;

import com.rpc.center.event.listener.EventListener;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Service;

@Service
public class AutoRegisterHelper implements BeanPostProcessor {
    @Autowired
    private EventManager register;

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof EventListener){
            EventListener listener=(EventListener)bean;
            register.addListener(listener.getEventType(),listener);
        }
        return bean;
    }
}
